
import javax.swing.tree.TreeNode;
import java.util.Scanner;
/*递归创建二叉树，脑子要炸掉了wc*/
class TreeNode1{
    public char val;
    public TreeNode left;
    public TreeNode right;
}

public class Tree {

    private char val;

    public void TreeNode1(char val){
            this.val = val;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);//实例化
        while (in.hasNextLine()) { // 因为（前序遍历）输入字符串 直接用hasNextLin去判断，有则返回true
            String str = in.nextLine();  //接收字符串
            TreeNode root = createTree(str);//先创建树再有遍历啊
            inOrder(root);
        }
    }
    public static int i = 0;

    //创建一棵树,静态成员方法，调用不依赖于对象
    public static TreeNode createTree(String str){
        TreeNode root = null;//因为最后读取的#字符没有进入if语句，所以直接返回null了6666
        if(str.charAt(i) != '#'){
            root = new TreeNode(str.charAt(i)); //这里他喵的为什么一定要先给root置空啊
            i++;
            root.left = createTree(str);
            root.right = createTree(str);

        }else{
            i++;

        }

        return root;
    }

    //中序遍历，void就行
    public static void inOrder(TreeNode root){  //inOrder方法传参肯定是传根节点呀，前序遍历肯定是打印为主嘛
        if(root == null){
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);

    }

}